package com.zx.yixun.ui

import android.os.Bundle
import android.text.TextUtils
import android.util.Log
import androidx.appcompat.widget.Toolbar
import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.ToastUtils
import com.tencent.bugly.beta.Beta
import com.zx.yixun.R
import com.zx.yixun.util.DataStoreUtil
import com.zx.yixun.util.MyUtils
import com.zx.ymy.base.BaseActivity
import com.zx.ymy.net.NetWorkHelper
import com.zx.ymy.net.api.MyApi
import kotlinx.android.synthetic.main.activity_login.*

class LoginActivity :BaseActivity() {
    override fun getToolbar(): Toolbar? {
        return null
    }

    override fun getContentId(): Int {
        return R.layout.activity_login
    }

    override fun onContentCreate(savedInstanceState: Bundle?) {
        tv_login.setOnClickListener {
            if (TextUtils.isEmpty(et_account.text.toString())||TextUtils.isEmpty(et_pwd.text.toString())){
                ToastUtils.showShort("请填写完整!")
                return@setOnClickListener
            }
            toLogin();
        }

        tv_upgrade.setOnClickListener {
            Beta.checkUpgrade(false,false);
        }
    }

    private fun toLogin() {
            NetWorkHelper.instance().createApi(MyApi::class.java).passwordLogin(et_account.text.toString(),et_pwd.text.toString())
                .runRxLoading({
                    it.let {
                        DataStoreUtil.saveToken(it?.token)
                        if (DataStoreUtil.getScreenType()==1){
                            //线头屏
                            ActivityUtils.startActivity(MainControlActivity::class.java)
                        }else{
                            //人工屏
                            if (DataStoreUtil.getIsPeopleSet()){
                                ActivityUtils.startActivity(EsopActivity::class.java)
                            }else{
                                ActivityUtils.startActivity(SetPeopleActivity::class.java)
                            }
                        }
                        finish()
                    }
                })
    }
}